import { GCellRenderer } from "../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../common/ObjCreate";
import { TToplist } from "../../../../Message/Db/Tables/TToplist";
import { Cache } from "../../cache/Cache";
import { SEntityId } from "../../../../Message/Public/SEntityId";
import { SPublicMiniPlayer } from "../../../../Message/Public/SPublicMiniPlayer";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { ColorConfig } from "../../resource/ColorConfig";
import { GameDefConfig } from "../../resource/GameDefConfig";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { EventName } from "../../mvc/EventName";
import { DataEvent } from "../../events/DataEvent";
import { PlayerMiniInfo } from "../../model/PlayerMiniInfo";
import { PlayerOpRegister } from "../common/menu/PlayerOpRegister";
type int = number;
//class TotalLoadRewardCellRenderer
    
    export  class TotalLoadRewardCellRenderer extends GCellRenderer
    {
        constructor()
        {
            super();
            this.initView();
            this.addEventListener(flash.events.MouseEvent.CLICK, this.onClick);
            return;
        }

        /* internal  */initView(): void
        {
            ObjCreate.createLabel("", 0, 0, 240, 25, flash.text.TextFormatAlign.LEFT, this);
            this._rangeTx = ObjCreate.createTextField("", 6, 0, 20, 20, this);
            this._nameTx = ObjCreate.createTextField("", 26, 0, 100, 20, this);
            this._campTx = ObjCreate.createTextField("", 131, 0, 30, 20, this);
            this._levelTx = ObjCreate.createTextField("", 172, 0, 20, 20, this);
            this._daysTx = ObjCreate.createTextField("", 200, 0, 40, 20, this);
            var loc1;
            this._rangeTx.autoSize = loc1 = flash.text.TextFormatAlign.CENTER;
            this._daysTx.autoSize = loc1 = loc1;
            this._levelTx.autoSize = loc1 = loc1;
            this._campTx.autoSize = loc1 = loc1;
            this._nameTx.autoSize = loc1 = loc1;
            this._rangeTx.autoSize = loc1;
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            super.data = arg1;
            this._info = arg1 as TToplist;
            if (this._info) 
            {
                this._serverId = Cache.instance.ranking.serverId;
                this._sEntityId = new SEntityId();
                this._sEntityId.id = this._info.entityId;
                this._sEntityId.type = 1;
                this._sEntityId.typeEx = this._serverId;
                this._sEntityId.typeEx2 = Cache.instance.role.entityInfo.entityId.typeEx2;
                this._sMiniPlayer = new SPublicMiniPlayer();
                this._sMiniPlayer.camp = this._info.propertyOne;
                this._sMiniPlayer.sex = this._info.propertyTwo;
                this._sMiniPlayer.career = this._info.propertyThree;
                this._sMiniPlayer.name = this._info.entityName;
                this._sMiniPlayer.level = this._info.valueTwo;
                this._sMiniPlayer.entityId = this._sEntityId;
                this._rangeTx.htmlText = HTMLUtil.addColor(this._info.rank.toString(), ColorConfig.instance.getCountryColor(this._info.propertyOne).color);
                this._nameTx.htmlText = HTMLUtil.addColor(this._info.entityName.toString(), ColorConfig.instance.getCountryColor(this._info.propertyOne).color);
                this._campTx.htmlText = HTMLUtil.addColor(GameDefConfig.instance.getECamp(this._info.propertyOne), ColorConfig.instance.getCountryColor(this._info.propertyOne).color);
                this._levelTx.htmlText = HTMLUtil.addColor(this._info.valueTwo.toString(), ColorConfig.instance.getCountryColor(this._info.propertyOne).color);
                this._daysTx.htmlText = HTMLUtil.addColor(this._info.valueOne.toString(), ColorConfig.instance.getCountryColor(this._info.propertyOne).color);
            }
            return;
        }

        public /* override */ set selected(arg1: Boolean)
        {
            if (!arg1) 
            {
                this.clearBgColor();
                Dispatcher.removeEventListener(EventName.TotalLoadRewardRankOnlinePlayerShowMenu, this.onTotalLoadRewardRankOnlinePlayerShowMenu);
            }
            return;
        }

        /* internal  */onTotalLoadRewardRankOnlinePlayerShowMenu(arg1: DataEvent): void
        {
            this.registerPlayerMenu(1);
            return;
        }

        public registerPlayerMenu(arg1: int): void
        {
            this._sMiniPlayer.online = arg1;
            this._playerMiniInfo = null;
            this._playerMiniInfo = new PlayerMiniInfo(this._sMiniPlayer);
            if (!(this._sMiniPlayer == null) && this._sMiniPlayer.online == 1) 
            {
                PlayerOpRegister.ShowOpList(this._playerMiniInfo, this._x, this._y);
            }
            return;
        }

        protected onClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.CheckTotalLoadRewardRankPlayer, this._sEntityId));
            Dispatcher.addEventListener(EventName.TotalLoadRewardRankOnlinePlayerShowMenu, this.onTotalLoadRewardRankOnlinePlayerShowMenu);
            this.drawGrayColor();
            this._x = arg1.stageX;
            this._y = arg1.stageY;
            return;
        }

        public drawGrayColor(): void
        {
            var loc1=null;
            var loc2=null;
            this._isDraw = true;
            if (this._bgBitmap == null) 
            {
                this._bgBitmap = new Object /* flash.display.Bitmap */();
                loc1 = new Object /* flash.display.Shape */();
                loc1.graphics.beginFill(11661311, 0.2);
                loc1.graphics.lineStyle(1, 11661311, 0);
                loc1.graphics.drawRoundRect(0, 0, 240, 20, 5, 5);
                loc1.cacheAsBitmap = true;
                loc2 = new Object /* flash.display.BitmapData */(240, 20, true, 0);
                loc2.draw(loc1);
                this._bgBitmap.bitmapData = loc2;
                this._bgBitmap.x = 6;
            }
            addChildAt(this._bgBitmap, 0);
            return;
        }

        public clearBgColor(): void
        {
            this._isDraw = false;
            if (this._bgBitmap && this._bgBitmap.parent) 
            {
                removeChild(this._bgBitmap);
            }
            return;
        }

        /* internal */ /* var */_rangeTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_nameTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_campTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_levelTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_daysTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_info: TToplist;

        protected /* var */_sEntityId: SEntityId;

        protected /* var */_serverId: int;

        protected /* var */_sMiniPlayer: SPublicMiniPlayer;

        protected /* var */_playerMiniInfo: PlayerMiniInfo;

        protected /* var */_isDraw: Boolean=false;

        /* internal */ /* var */_x: number=600;

        /* internal */ /* var */_y: number=135;

        protected /* var */_bgBitmap: Object /* flash.display.Bitmap */;
    }
